package com.ww.springboot.boot.algorithm.leetcode1;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

/**
 * todo
 *
 * @author wanwei
 * @since 2022-03-16 14:30
 */
public class AT78子集 {

    public static void main(String[] args) {

        int[] arrays = {1,2,3};
        Deque<Integer> path = new ArrayDeque<>();
        List<List<Integer>> list = new ArrayList<>();
        subsets2(arrays, 0, path, list);
        System.out.println(list);
    }


    /**
     * 1.分别求出 1,2...n个数组合的可能 最后全部相加
     *
     * @param nums
     * @return
     */
    public List<List<Integer>> subsets(int[] nums) {


        return null;
    }

    /**
     * 二叉树
     * 遍历数组 每取一个都有使用和不使用两种可能
     *
     * @param nums
     * @return
     */
    public static void subsets2(int[] nums, int index, Deque deque, List<List<Integer>> list) {
        if (index == nums.length) {
            list.add(new ArrayList<>(deque));
            return;
        }
        subsets2(nums, index + 1, deque, list);
        deque.addLast(nums[index]);
        subsets2(nums, index + 1, deque, list);
        deque.removeLast();
    }
}
